﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.SharePoint.Linq;
using ZhukBlogLinqExamples.Model;

namespace ZhukBlogLinqExamples.Repositories
{
    /// <summary>
    /// Repository for Employees list
    /// </summary>
    public class EmployeeRepository
        : BaseRepository<Employee, DataContext>
    {
        /// <summary>
        /// List' name
        /// </summary>
        private const string EmployeeListName = "Employees";

        /// <summary>
        /// Create instance for current web in NOT readonly mode
        /// </summary>
        public EmployeeRepository()
            : base(EmployeeListName) { }
        /// <summary>
        /// Create instance for current web
        /// </summary>
        public EmployeeRepository(bool readOnly)
            : base(EmployeeListName, readOnly) { }
        /// <summary>
        /// Create instance for specific web in NOT readonly mode
        /// </summary>
        /// <param name="webUrl">web' URL</param>
        public EmployeeRepository(string webUrl)
            : base(EmployeeListName, webUrl) { }
        /// <summary>
        /// Create instance for specific web
        /// </summary>
        /// <param name="webUrl">web' URL</param>
        /// <param name="readOnly">true - ReadOnly mode, false - NOT ReadOnly mode</param>
        public EmployeeRepository(string webUrl, bool readOnly)
            : base(EmployeeListName, webUrl, readOnly) { }
        /// <summary>
        /// Create instance for another site collection
        /// </summary>
        /// <param name="webUrl">web' URL</param>
        /// <param name="readOnly">true - ReadOnly mode, false - NOT ReadOnly mode</param>
        /// <param name="crossSite">true - another site collection, false - current site collection</param>
        public EmployeeRepository(string webUrl, bool readOnly, bool crossSite)
            : base(EmployeeListName, webUrl, readOnly, crossSite) { }

        /// <summary>
        /// Retrieving subornidates for employee
        /// </summary>
        /// <param name="managerId">employee Id</param>
        public IEnumerable<Employee> GetEmployees(int managerId)
        {
            return GetEntityCollection(emp => emp.ManagerId == managerId);
        }
    }
}
